﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：FundsOperatingInfo
// 文件功能描述：增减款
//
// 
// 创建标识：2012-03-07 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class FundsOperatingInfo
    {
        /// <summary>
        /// 卡流水号
        /// </summary>
        public int CardNo
        {
            get;
            set;
        }
        /// <summary>
        /// 人员编号
        /// </summary>
        public string EmpNo
        {
            get;
            set;
        }
        /// <summary>
        /// 人员姓名
        /// </summary>
        public string PName
        {
            get;
            set;
        }
        /// <summary>
        /// 卡序列号
        /// </summary>
        public Int64 CardSerial
        {
            get;
            set;
        }
        /// <summary>
        /// 部门名称
        /// </summary>
        public string deptName
        {
            get;
            set;
        }
        /// <summary>
        /// 卡类型（人员类型）
        /// </summary>
        public string PersonTypeName
        {
            get;
            set;
        }
        /// <summary>
        /// 消费余额
        /// </summary>
        public decimal Balance
        {
            get;
            set;
        }
        /// <summary>
        /// 要增减款的卡流水号的集合
        /// </summary>
        public string CardNoAdd
        {
            get;
            set;
        }
        /// <summary>
        /// 增减类型编号
        /// </summary>
        public int DepositTypeID
        {
            get;
            set;
        }
        /// <summary>
        /// 增减类型名称
        /// </summary>
        public string DepositName
        {
            get;
            set;
        }
        /// <summary>
        /// 增减金额
        /// </summary>
        public decimal Money
        {
            get;
            set;
        }
        /// <summary>
        /// 操作员号
        /// </summary>
        public string OperatorID
        {
            get;
            set;
        }

        private DataAccessFundsOperating dar;
        private int FundsOperatingcount;
        public int _FundsOperatingcount
        {
            get { return FundsOperatingcount; }
        }
        public FundsOperatingInfo(bool isgetcount)
        {
            dar = new DataAccessFundsOperating();
            if (isgetcount)
            {
                FundsOperatingcount = GetFundsOperatingCount();
            }
        }
        public FundsOperatingInfo()
        { }

        /// <summary>
        /// 获取所有销卡的数量
        /// </summary>
        /// <returns></returns>
        private int GetFundsOperatingCount()
        {
            return dar.GetFundsOperatingCount();
        }

        /// <summary>
        /// 获取所有销卡的数量
        /// </summary>
        /// <returns></returns>
        public int GetFundsOperatingCount(string where)
        {
            return dar.GetFundsOperatingCount(where);
        }

        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            return dar.GetdeptName();
        }
        /// <summary>
        /// 获取增减名称列表（用于绑定下拉框,增款界面下）
        /// </summary>
        /// <returns></returns>
        public DataSet GetDepositTypeIDIncrease()
        {
            return dar.GetDepositTypeIDIncrease();
        }
        /// <summary>
        /// 获取增减名称列表（用于绑定下拉框,减款界面下）
        /// </summary>
        /// <returns></returns>
        public DataSet GetDepositTypeIDReduce()
        {
            return dar.GetDepositTypeIDReduce();
        }

        /// <summary>
        /// 获取已发卡且状态为正常的卡的列表（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<FundsOperatingInfo> SelFundsOperatingInfo(int pagesize, int startindex, string strquery)
        {
            IList<FundsOperatingInfo> funlist = new List<FundsOperatingInfo>();
            FundsOperatingInfo funinfo;
            DataSet ds = dar.SelFundsOperatingInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                funinfo = new FundsOperatingInfo()
                {
                    CardNo = Convert.ToInt32(item["CardNo"]),
                    EmpNo = item["EmpNo"].ToString(),
                    PName = item["PName"].ToString(),
                    CardSerial = Convert.ToInt64(item["CardSerial"]),
                    deptName = item["deptName"].ToString(),
                    PersonTypeName = "员工卡",
                    Balance = (Convert.ToDecimal(item["Balance"])) / 100
                };
                funlist.Add(funinfo);
            }
            return funlist;
        }

        public IList<FundsOperatingInfo> SelLeftBox(string strquery)
        {
            IList<FundsOperatingInfo> funlist = new List<FundsOperatingInfo>();
            FundsOperatingInfo funinfo;
            DataSet ds = dar.SelLeftBox(strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                funinfo = new FundsOperatingInfo()
                {
                    EmpNo = item["EmpNo"].ToString(),
                    PName = item["PName"].ToString()
                };
                funlist.Add(funinfo);
            }
            return funlist;
        }

        public int SaveIncreaseMoney(FundsOperatingInfo fun, string[] sempall, out int countNo)
        {
            object[] obj = new object[] { fun.DepositName, fun.Money, fun.OperatorID };
            return dar.SaveIncreaseMoney(obj, sempall, out countNo);
        }

        public int SaveReduceMoney(FundsOperatingInfo fun, string[] sempall)
        {
            object[] obj = new object[] { fun.DepositName, fun.Money, fun.OperatorID };
            return dar.SaveReduceMoney(obj, sempall);
        }

        public bool CheckMoney(decimal Money, string CardNoAdd)
        {
            decimal demoney = dar.CheckMoney(CardNoAdd);
            return Money > demoney ? false : true;
        }
    }
}
